package com.note.servlet.note;

import com.note.pojo.Note;
import com.note.pojo.Notetype;
import com.note.service.note.noteService;
import com.note.service.note.noteServiceImpl;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

public class editShow extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int noteId = Integer.parseInt(req.getParameter("noteId"));
        noteService a = new noteServiceImpl();
        HashMap map = a.edit(noteId);
        Note note = (Note)map.get("note");
        List<Notetype> typeList = (List<Notetype>) map.get("typeList");
        req.setAttribute("note", note);
        req.setAttribute("typeList", typeList);
        req.getRequestDispatcher("noteEdit.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
